package com.crr.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {
    /**
     *准换json格式
     * @param response
     * @param request
     * @param o
     */
    public static void getJson(HttpServletResponse response, HttpServletRequest request, Object o) {
    /*    response.setContentType("text/html;charset=UTF-8");*/
        response.setContentType("application/json;charset=UTF-8");
        response.setHeader("Params", "No-cache");
        response.setDateHeader("Expires", -10);
        PrintWriter out = null;
        try {
            out = response.getWriter();
            String jsonstr = JSON.toJSONString(o);
            out.println(jsonstr);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            out.close();
        }

    }
}
